import {
  birdNamesQuery,
  queryBirdThematic
  } from 'api/birdsProject';
import React from "react";

  export default {
      namespace: 'birdsProject',
      state: {
        birdNames: [{code:1,name:"黑鹳"},
          {code:2,name:"东方白鹤"},
          {code:14,name:"黄嘴白鹭"}],
        bridsProjectMap: []
      },

      effects: {
        *birdNamesQuery({ payload }, { call, put }) {
          const result = yield call(birdNamesQuery, payload)
          if (result && result.success) {
            yield put({
              type: 'setState',
              payload: {
                birdNames: result.data,
              },
            })
          } else {
            throw data
          }
        },
        *arcgisFeatureServerQuery({ payload }, { call, put }) {
          const data = yield call(queryBirdThematic, payload)
          if (data && data.features) {
            yield put({
              type: 'setState',
              payload: {
                bridsProjectMap: data.features,
              },
            })
            return data;
          } else {
            // throw data
            return data;
          }
        },
      },

      reducers: {
        setState(state, action) {
          return {
              ...state,
              ...action.payload
          };
        }
      },
    }
